const mongoose = require("mongoose");

//定义字段
const shopSchema = new mongoose.Schema({
    name: String,
    shops: String,
    price: Number,
    yunfei: Number
})

//创建可node操作模型
const shopModel = mongoose.model("shop",shopSchema)

//创建计算page&count的函数
function findlist(page,count){
    return new Promise((resolve,reject)=>{

        //先计算总页数
        shopModel.find().count()
        .then(
            (result)=>{
                let pages = Math.ceil(result/count);
                
                //再查询数据
                let opage = (page-1)*count;
                shopModel.find().skip(opage).limit(count)
                .then(
                    (result)=>{
                        //输出 总页数pages & 数据result
                        resolve({result,pages})
                    }
                )

            }
        )
    })
}

//模块输出函数
module.exports = {findlist}